package com.etlmaster.executor.utils;



import com.etlmaster.executor.utils.LogWriter;
import com.etlmaster.jdbc.JdbcTemplate;



/**
 * @author Larry
 * @copyright Larry@etlMaster
 * @since 2017-09-10
 */
public class HiveUtil {
	public static String executeSql(JdbcTemplate jdbcTemplate,String sql) throws Exception {
		String flag = "true";
	    try {
	      jdbcTemplate.execute(sql);
	    }catch(Exception e){
	    	if(e.getMessage().contains("No files matching path"))
	    		flag="File does not exist";
	    	else
	    	{flag = e.getMessage();}
	    	LogWriter.addLog("ERROR","{}",e.getMessage());
	    }
	    return flag.replaceAll("'", "\"");
	}
	public static boolean query(JdbcTemplate jdbcTemplate,String sql){
		boolean flag = true;
	    try {
	      
	    	LogWriter.addLog("INFO",sql);
	      jdbcTemplate.execute(sql);
	    }catch(Exception e){
	    	flag=false;
	    	LogWriter.addLog("ERROR",e.getMessage());
	    }
	    return flag;
	}
	  
	public static HiveUtil getInstance()
	{
	    return SingletonHolder.instance;
	}

	static class SingletonHolder
	{
	   static HiveUtil instance = new HiveUtil();
	}


}
